#pragma once

#include "skia_control_base.h"

#include <functional>
#include <string>

#include <include/core/SkRect.h>
#include <include/core/SkColor.h>

#include "skia_control_down.h"
#include "skia_control_hover.h"

namespace SkiaControl {
class Button : public SkiaControlBase, public SkiaControlHover, public SkiaControlDown {
public:
    ~Button() override = default;

    class Builder {
    public:
        Builder();
        void SetRegion(const SkRect &region);
        void SetColor(const SkColor &color);
        void SetText(const std::string &text);
        std::shared_ptr<Button> Build();

    private:
        std::shared_ptr<Button> buildingButton_ = nullptr;
    };

    using OnClickFunc = std::function<void()>;
    void SetOnClickFunc(const OnClickFunc &onClick) { onClick_ = onClick; }

    bool IsContain(int32_t x, int32_t y) override;
    void OnMouseMotion(int32_t x, int32_t y) override;
    void OnMouseDown(int32_t x, int32_t y) override;
    void OnMouseUp() override;
    void OnClick(int32_t x, int32_t y) override;
    void OnDraw(SkCanvas &canvas) override;

private:
    friend class Builder;
    Button() = default;

    SkRect region_ = SkRect::MakeEmpty();
    SkColor color_ = SK_ColorLTGRAY;
    std::string text_ = "button";
    OnClickFunc onClick_ = nullptr;
};
} // namespace SkiaControl
